package com.joy.ogljoy_01.opengl.ui;

import com.joy.ogljoy_01.opengl.proto.RectangleF;
import com.joy.ogljoy_01.opengl.util.Utils;

public class FPS {
	private Image imgNum;
	/** 裁剪区域 */
	private RectangleF clipRect;
	
	private float time;
	private int count;
	private int num;
	
	public static FPS create() {
		FPS fps = new FPS();
	
		fps.init();
		
		return fps;
	}
	
	private void init() {
		imgNum = Image.create("num.png");
		clipRect = new RectangleF(0, 0, imgNum.width()/10f, imgNum.height());
	}
	
	public void update(float dt) {
		count ++;
		time += dt;
		if(time > 1) {
			num = count;
			
			time -= 1;
			count = 0;
		}

		int tNum[] = Utils.int2Array(num);
		for(int i=0; i<tNum.length; i++) {
			clipRect.x = tNum[i] * clipRect.width;
			imgNum.draw(clipRect.width*i, 0, clipRect);
		}
	}
}
